home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Digital Editor Plugs / FadeNote.c < prev    next >
C/C++ Source or Header  |  1995-09-25  |  6KB  |  277 lines

  1. /*    Fade In Vol        */
  2. /*    v 1.0            */
  3. /*    1995 by ANR        */
  4.  
  5. //    Usage:
  6. //    A small example of to use Digital Editor Plugs with a MODAL DIALOG
  7.  
  8. #include "MAD.h"
  9. #include "PPPlug.h"
  10.  
  11. #if defined(powerc) || defined(__powerc)
  12. enum {
  13.         PlayerPROPlug = kCStackBased
  14.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  15.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Pcmd*)))
  16.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( PPInfoPlug*)))
  17. };
  18.  
  19. ProcInfoType __procinfo = PlayerPROPlug;
  20. #else
  21. #include <A4Stuff.h>
  22. #endif
  23.  
  24. void GetDText (DialogPtr dlog, short item, StringPtr str)
  25. {
  26. Handle    itemHandle;
  27. short    itemType;
  28. Rect    itemRect;
  29.  
  30.     GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
  31.     GetIText (itemHandle, str);
  32. }
  33.  
  34. void SetDText (DialogPtr dlog, short item, Str255 str)
  35. {
  36. Handle    itemHandle;
  37. short    itemType;
  38. Rect    itemRect;
  39.  
  40.     GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
  41.     SetIText (itemHandle, str);
  42. }
  43.  
  44. GDHandle    TheGDevice:0xCC8;
  45.  
  46. void AutoPosition( DialogPtr aDia)
  47. {
  48.     Point    Position, mouse;
  49.     Rect    ViewRect;
  50.     short    XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
  51.     
  52.     GetMouse( &mouse);
  53.     LocalToGlobal( &mouse);
  54.     
  55.     SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
  56.                         (*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
  57.     
  58.     Position.h = mouse.h - XSize/2;
  59.     if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
  60.     else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
  61.     
  62.     Position.v = mouse.v - YSize/2;
  63.     if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
  64.     else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
  65.     
  66.     MoveWindow( aDia, Position.h, Position.v, false);
  67.     
  68.     ShowWindow( aDia);
  69. }
  70.  
  71. Cmd* GetCmd( short row, short    track, Pcmd*    myPcmd)
  72. {
  73.     if( row < 0) row = 0;
  74.     else if( row >= myPcmd->length) row = myPcmd->length -1;
  75.  
  76.     if( track < 0) track = 0;
  77.     else if( track >= myPcmd->tracks) track = myPcmd->tracks -1;
  78.     
  79.     return( &(myPcmd->myCmd[ (myPcmd->length * track) + row]));
  80. }
  81.  
  82. void pStrcpy(register unsigned char *s1, register unsigned char *s2)
  83. {
  84.     register short len, i;
  85.     
  86.     len = *s2;
  87.     for ( i = 0; i <= len; i++) s1[ i] = s2[ i];
  88. }
  89.  
  90. void OctavesName(short    id, Str255    String)
  91. {
  92.     short            NNames[ 12] =    {'C ','C#','D ','D#','E ','F ','F#','G ','G#','A ','A#','B '};
  93.     Str255            WorkStr;
  94.     
  95.     if( id == 0xFF)
  96.     {
  97.         pStrcpy( String, "\p---");
  98.         return;
  99.     }
  100.     
  101.     NumToString( (id / 12), WorkStr);
  102.     String[ 0] = 3;
  103.     String[ 1] = NNames[ (id) % 12]>>8;
  104.     String[ 2] = NNames[ (id) % 12];
  105.       String[ 3] = WorkStr[ 1];
  106. }
  107.  
  108. MenuHandle CreateMenu()
  109. {
  110.     MenuHandle    returnMenu;
  111.     short        i;
  112.     Str255        aStr;
  113.     
  114.     returnMenu = GetMenu( 141);
  115.     
  116.     OctavesName( 1, aStr);        SetItem( returnMenu, 1, aStr);
  117.     for( i = 1; i < 96; i++)
  118.     {
  119.         OctavesName( i, aStr);
  120.         AppendMenu( returnMenu, aStr);
  121.     }
  122.     
  123.     return returnMenu;
  124. }
  125.  
  126. short Text2Note( Str255    myTT)
  127. {
  128.     short        Oct;
  129.  
  130.     Oct = myTT[ 3] - 48;
  131.     Oct *= 12;
  132.     
  133.     //    0    1     2     3     4     5     6     7      8     9     10     11
  134.     //    C-  C#   D-  D#  E-  F-  F#  G-  G#  A-  A#  B-
  135.     switch( myTT[1])
  136.     {
  137.         case 'C':    case'c':    Oct += 0;    break;
  138.         case 'D':    case'd':    Oct += 2;    break;
  139.         case 'E':    case'e':    Oct += 4;    break;
  140.         case 'F':    case'f':    Oct += 5;    break;
  141.         case 'G':    case'g':    Oct += 7;    break;
  142.         case 'A':    case'a':    Oct += 9;    break;
  143.         case 'B':    case'b':    Oct += 11;    break;
  144.         
  145.         default:    Oct = 0xFF;        break;
  146.     }
  147.     
  148.     if( Oct != 0xFF)
  149.     {
  150.         if( myTT[ 2] == '#') Oct++;
  151.         if( Oct >= 96) Oct = 0xFF;
  152.         if( Oct < 0) Oct = 0xFF;
  153.     }
  154.     
  155.     return( Oct);
  156. }
  157.  
  158. OSErr main(     Pcmd                    *myPcmd,
  159.                 PPInfoPlug                *thePPInfoPlug)
  160. {
  161.     DialogPtr            myDia;
  162.     short                itemHit, itemType;
  163.     Rect                itemRect;
  164.     Handle                itemHandle;
  165.     Str255                aStr;
  166.     MenuHandle            noteMenu;
  167.     Point                myPt;
  168.     long                Result;
  169.     
  170. #ifndef powerc
  171.     long    oldA4 = SetCurrentA4();             //this call is necessary for strings in 68k code resources
  172. #endif
  173.  
  174.     myDia = GetNewDialog( 128, 0L, (WindowPtr) -1L);
  175.     SetPort( myDia);
  176.     AutoPosition( myDia);
  177.  
  178.     SetDText( myDia, 3, "\pC 3");
  179.     SetDText( myDia, 4, "\pC 7");
  180.     SelIText( myDia, 3, 0, 200);
  181.     
  182.     noteMenu = CreateMenu();
  183.     
  184.     do
  185.     {
  186.         RESTART:
  187.     
  188.         #if defined(powerc) || defined(__powerc)
  189.         ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  190.         #else
  191.         ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  192.         #endif
  193.         
  194.         switch( itemHit)
  195.         {
  196.             case 7:
  197.             case 8:
  198.                 InsertMenu( noteMenu, hierMenu);
  199.                 
  200.                 GetDItem( myDia, itemHit, &itemType, &itemHandle, &itemRect);
  201.                 myPt.v = itemRect.top;    myPt.h = itemRect.left;
  202.                 LocalToGlobal( &myPt);
  203.                 
  204.                 GetDText( myDia, itemHit-4, aStr);
  205.                 SetItemMark( noteMenu, Text2Note( aStr) + 1, 0xa5);
  206.                 
  207.                 Result = PopUpMenuSelect(    noteMenu,
  208.                                             myPt.v,
  209.                                             myPt.h,
  210.                                             Text2Note( aStr) + 1);
  211.                 
  212.                 SetItemMark( noteMenu, Text2Note( aStr) + 1, 0);
  213.                 
  214.                 if ( HiWord( Result ) != 0 )
  215.                 {
  216.                     OSErr    iErr;
  217.                 
  218.                     OctavesName( LoWord( Result)-1, aStr);
  219.                     SetDText( myDia, itemHit-4, aStr);
  220.                     SelIText( myDia, 3, 0, 200);
  221.                 }
  222.                 
  223.                 DeleteMenu( (*noteMenu)->menuID);
  224.             break;
  225.         }
  226.     }while( itemHit != 1 && itemHit != 2);
  227.     
  228.     if( itemHit == 1)
  229.     {
  230.         short    track, row;
  231.         long    from, to;
  232.         Cmd        *myCmd;
  233.     
  234.         GetDText( myDia, 3, aStr);        from     = Text2Note( aStr);
  235.         GetDText( myDia, 4, aStr);        to         = Text2Note( aStr);
  236.         
  237.         // Check values
  238.         
  239.         if( from < 0 || from >= 96)
  240.         {
  241.             SelIText( myDia, 3, 0, 200);
  242.             SysBeep( 1);
  243.             goto RESTART;
  244.         }
  245.         
  246.         if( to < 0 || to >= 96)
  247.         {
  248.             SelIText( myDia, 4, 0, 200);
  249.             SysBeep( 1);
  250.             goto RESTART;
  251.         }
  252.         
  253.         for( track = 0; track < myPcmd->tracks; track++)
  254.         {
  255.             for( row = 0; row < myPcmd->length; row++)
  256.             {
  257.                 myCmd = GetCmd( row, track, myPcmd);
  258.                 
  259.                 if( myPcmd->length > 1)            // no zero div !!
  260.                     myCmd->note    = from + ((to-from) * row) / (myPcmd->length-1);
  261.                 
  262.                 // my fade command : 0x10 min vol, 0x50 : max vol
  263.                 // Refer to MAD description for more informations            
  264.             }
  265.         }
  266.     }
  267.     
  268.     DisposDialog( myDia);
  269.     
  270.     #ifndef powerc
  271.         SetA4( oldA4);
  272.     #endif
  273.  
  274.     ReleaseResource( (Handle) noteMenu);
  275.     
  276.     return noErr;
  277. }